{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n*****************\nSpecifying Colors\n*****************\n\nMatplotlib recognizes the following formats to specify a color:\n\n* an RGB or RGBA (red, green, blue, alpha) tuple of float values in ``[0, 1]``\n  (e.g., ``(0.1, 0.2, 0.5)`` or ``(0.1, 0.2, 0.5, 0.3)``);\n* a hex RGB or RGBA string (e.g., ``'#0f0f0f'`` or ``'#0f0f0f80'``;\n  case-insensitive);\n* a string representation of a float value in ``[0, 1]`` inclusive for gray\n  level (e.g., ``'0.5'``);\n* one of ``{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}``;\n* a X11/CSS4 color name (case-insensitive);\n* a name from the `xkcd color survey`_, prefixed with ``'xkcd:'`` (e.g.,\n  ``'xkcd:sky blue'``; case insensitive);\n* one of the Tableau Colors from the 'T10' categorical palette (the default\n  color cycle): ``{'tab:blue', 'tab:orange', 'tab:green', 'tab:red',\n  'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan'}``\n  (case-insensitive);\n* a \"CN\" color spec, i.e. `'C'` followed by a number, which is an index into\n  the default property cycle (``matplotlib.rcParams['axes.prop_cycle']``); the\n  indexing is intended to occur at rendering time, and defaults to black if the\n  cycle does not include color.\n\n\n\"Red\", \"Green\", and \"Blue\" are the intensities of those colors, the combination\nof which span the colorspace.\n\nHow \"Alpha\" behaves depends on the ``zorder`` of the Artist.  Higher\n``zorder`` Artists are drawn on top of lower Artists, and \"Alpha\" determines\nwhether the lower artist is covered by the higher.\nIf the old RGB of a pixel is ``RGBold`` and the RGB of the\npixel of the Artist being added is ``RGBnew`` with Alpha ``alpha``,\nthen the RGB of the pixel is updated to:\n``RGB = RGBOld * (1 - Alpha) + RGBnew * Alpha``.  Alpha\nof 1 means the old color is completely covered by the new Artist, Alpha of 0\nmeans that pixel of the Artist is transparent.\n\nFor more information on colors in matplotlib see\n\n* the :doc:`/gallery/color/color_demo` example;\n* the `matplotlib.colors` API;\n* the :doc:`/gallery/color/named_colors` example.\n\n\"CN\" color selection\n--------------------\n\n\"CN\" colors are converted to RGBA as soon as the artist is created.  For\nexample,\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib as mpl\n\nth = np.linspace(0, 2*np.pi, 128)\n\n\ndef demo(sty):\n    mpl.style.use(sty)\n    fig, ax = plt.subplots(figsize=(3, 3))\n\n    ax.set_title('style: {!r}'.format(sty), color='C0')\n\n    ax.plot(th, np.cos(th), 'C1', label='C1')\n    ax.plot(th, np.sin(th), 'C2', label='C2')\n    ax.legend()\n\ndemo('default')\ndemo('seaborn')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "will use the first color for the title and then plot using the second\nand third colors of each style's ``mpl.rcParams['axes.prop_cycle']``.\n\n\n\nxkcd v X11/CSS4\n---------------\n\nThe xkcd colors are derived from a user survey conducted by the\nwebcomic xkcd.  `Details of the survey are available on the xkcd blog\n<https://blog.xkcd.com/2010/05/03/color-survey-results/>`__.\n\nOut of 148 colors in the CSS color list, there are 95 name collisions\nbetween the X11/CSS4 names and the xkcd names, all but 3 of which have\ndifferent hex values.  For example ``'blue'`` maps to ``'#0000FF'``\nwhere as ``'xkcd:blue'`` maps to ``'#0343DF'``.  Due to these name\ncollisions all of the xkcd colors have ``'xkcd:'`` prefixed.  As noted in\nthe blog post, while it might be interesting to re-define the X11/CSS4 names\nbased on such a survey, we do not do so unilaterally.\n\nThe name collisions are shown in the table below; the color names\nwhere the hex values agree are shown in bold.\n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import matplotlib._color_data as mcd\nimport matplotlib.patches as mpatch\n\noverlap = {name for name in mcd.CSS4_COLORS\n           if \"xkcd:\" + name in mcd.XKCD_COLORS}\n\nfig = plt.figure(figsize=[4.8, 16])\nax = fig.add_axes([0, 0, 1, 1])\n\nfor j, n in enumerate(sorted(overlap, reverse=True)):\n    weight = None\n    cn = mcd.CSS4_COLORS[n]\n    xkcd = mcd.XKCD_COLORS[\"xkcd:\" + n].upper()\n    if cn == xkcd:\n        weight = 'bold'\n\n    r1 = mpatch.Rectangle((0, j), 1, 1, color=cn)\n    r2 = mpatch.Rectangle((1, j), 1, 1, color=xkcd)\n    txt = ax.text(2, j+.5, '  ' + n, va='center', fontsize=10,\n                  weight=weight)\n    ax.add_patch(r1)\n    ax.add_patch(r2)\n    ax.axhline(j, color='k')\n\nax.text(.5, j + 1.5, 'X11', ha='center', va='center')\nax.text(1.5, j + 1.5, 'xkcd', ha='center', va='center')\nax.set_xlim(0, 3)\nax.set_ylim(0, j + 2)\nax.axis('off')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
